package com.sense.kukoo.biz_media.vm

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.sense.kukoo.biz_media.model.PodcastDetailModel
import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.mvvm.vm.BaseViewModel
import com.sense.kukoo.common.repo.bean.BookItemBean

class PodcastDetailViewModel:BaseViewModel() {

    private val TAG: String = javaClass.simpleName
    private lateinit var mModel: PodcastDetailModel

    val action_back: MutableLiveData<Boolean> = MutableLiveData()
    val action_download: MutableLiveData<Boolean> = MutableLiveData()
    val action_share: MutableLiveData<Boolean> = MutableLiveData()

    val data_bookitem:MutableLiveData<BookItemBean> = MutableLiveData()

    override fun createModel(): BaseMvvmModel {
        mModel = PodcastDetailModel()
        return mModel
    }

    override fun initData() {}

    fun onBack(){
        action_back.postValue(true)
    }

    fun onShare(){
        action_share.postValue(true)
    }

    fun onDownload(){
        action_download.postValue(true)
    }

    fun loadData(book_id: Long, chapter:Int){
        toView(ACTION_SHOW_DIALOG)
        request {
            val getThisChapter = mModel.getThisChapter(book_id, chapter)
            if (getThisChapter.success) {
                val data = getThisChapter.data!!
                if(data.records.size >= 1){
                    val music: BookItemBean = data.records[0]
                    data_bookitem.postValue(music)
                }
            } else {
                Log.e(TAG, "result=" + getThisChapter.msg)
                getThisChapter.msg.let { sendHintMessage(it) }
            }
            toView(ACTION_HIDE_DIALOG)
        }
    }

}